<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('申请开票列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>合同编号：</label>
                                <input type="text" autoComplete="off" name="orderNo"/>
                            </li>
                            <li>
                                <label>项目名称：</label>
                                <input type="text" autoComplete="off" name="xmmc"/>
                            </li>
                            <li>
                                <label>申请时间：</label>
                                <input type="text" autoComplete="off" class="time-input" placeholder="请选择申请时间" name="sqsj"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
<!--                 <a class="btn btn-primary single disabled" onclick="$.operate.editTab()" shiro:hasPermission="gcgl:sqkp:edit"> -->
<!--                     <i class="fa fa-edit"></i> 修改 -->
<!--                 </a> -->
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="gcgl:sqkp:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="gcgl:sqkp:export">
                    <i class="fa fa-download"></i> 导出
                </a>
                <a class="btn btn-success single disabled" onclick="sqkpfpadd()" shiro:hasPermission="gcgl:sqkpfp:add">
                    <i class="fa fa-edit"></i> 上传销项发票
                </a>
<!--                 <a class="btn btn-success single disabled" onclick="sqkpprint()" shiro:hasPermission="gcgl:sqkp:print"> -->
<!--                     <i class="fa fa-download"></i> 打印开票申请单 -->
<!--                 </a> -->
                <a class="btn btn-info single disabled" id="button-yes" shiro:hasPermission="gcgl:qrsk:add">
                    <i class="fa fa-check"></i> 确认收款
                </a>
                <a class="btn btn-info single disabled" id="button-lis" shiro:hasPermission="gcgl:qrsk:view">
                    <i class="fa fa-check"></i> 查看收款台账
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('gcgl:sqkp:edit')}]];
        var removeFlag = [[${@permission.hasPermi('gcgl:sqkp:remove')}]];
        var types = [[${@dict.getType('gcgl_project_type')}]];
        var fps = [[${@dict.getType('gcgl_project_fp')}]];
    	var statuss = [[${@dict.getType('sj_contract_status')}]];
    	
//     	var statuss = [[${@dict.getType('sj_chance_status')}]];
	    	
        var prefix = ctx + "gcgl/sqkp";

        $(function() {
            var options = {
                url: prefix + "/list",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "申请开票",
                sortName: "id desc",
                sortOrder: "",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '主键'
                },
                {
                    field: 'gcProjectid',
                    title: '合同ID',
                    visible: false
                },
                {
                    field: 'orderNo',
                    title: '合同编号'
                },
                {
                    field: 'xmmc',
                    title: '项目名称'
                },
                {
                    field: 'sqsj',
                    title: '申请时间'
                },
                {
                    field: 'xmfzr',
                    title: '项目负责人'
                },
                {
                    field: 'htje',
                    title: '合同金额',
                    visible: false
                },
                {
		            field: 'xmlx',
		            title: '项目类型',
		            formatter: function(value, item, index) {
		            	return $.table.selectDictLabel(types, item.xmlx);
		            }
		        },
                {
                    field: 'bcsqkpje',
                    title: '本次申请开票金额',
                    visible: false
                },
                {
                    field: 'yjskje',
                    title: '预计收款金额',
                    visible: false
                },
                {
		            field: 'fplx',
		            title: '发票类型',
		            formatter: function(value, item, index) {
		            	return $.table.selectDictLabel(fps, item.fplx);
		            }
		        },
                {
                    field: 'shuih',
                    title: '单位信息名称/税号',
                    visible: false
                },
                {
                    field: 'kaihuh',
                    title: '单位信息开户行/帐号',
                    visible: false
                },
                {
                    field: 'dizhi',
                    title: '单位信息地址/电话',
                    visible: false
                },
                {
                    field: 'ykfpsj',
                    title: '已开发票时间',
                    visible: false
                },
                {
                    field: 'itemje',
                    title: '申请开票金额',
                    visible: false
                },
                {
                    field: 'ykfpje',
                    title: '已开发票金额',
                    visible: false
                },
                {
                    field: 'hej',
                    title: '合计(累计开票金额)',
                    visible: false
                },
                {
                    field: 'sqrpr',
                    title: '分管领导批准',
                    visible: false
                },
                {
                    field: 'cwkpr',
                    title: '财务开票人',
                    visible: false
                },
                {
                    field: 'zjlsp',
                    title: '总经理批准',
                    visible: false
                },
                {
                    field: 'owner',
                    title: '申请人'
                },
                {
                    field: 'dept',
                    title: '申请部门'
                },
                {
		            field: 'status',
		            title: '状态',
		            formatter: function(value, item, index) {
		            	return $.table.selectDictLabel(statuss, item.status);
		            }
		        },
                {
                    field: 'spyj',
                    title: '审批意见',
                    visible: false
                },
                {
                    title: '操作',
                    align: 'center',
                    width: '200px',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                    	if(row.status==1){
                        	actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        }else if(row.status==4){
                        	actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        }
                    	actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="run(\'' + row.processInstanceId + '\')"><i class="fa fa-file-archive-o"></i>流程进度</a>&nbsp;');
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="sqkpprint(\'' + row.id + '\')"><i class="fa fa-edit"></i>查看</a> ');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        
        //确认收款
        $("#button-yes").click(function(){
        	table.set();
        	var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            
            if (rows.length > 1) {
                $.modal.alertWarning("请只选择一条记录");
                return;
            }
            
            var status = $.table.selectColumns("status");
            
            if(status==3){
            	$.modal.open('确认收款',"/gcgl/qrsk/add/"+rows.join());
            	/**
            	$.modal.confirm("确认该款项收款吗?", function() {
    	    		$.ajax({
        				url: "/gcgl/sqkp/hjconfirm",
        				type: "post",
        				data: { "ids": rows.join() },
        				dataType: 'json',
        				success: function(data) {
        					$.table.refresh();
        				},
        				error: function(xhr, type, errorThrown) {
        					//异常处理；
        					$.modal.alert("请稍后再试！");
        					$.table.refresh();
        				}
        			});
    	    	});
            	**/
            }else if(status==9){
            	$.modal.alertWarning("该记录已付款完成！");
                return;
            }else{
            	$.modal.alertWarning("该记录未审核通过！");
                return;
            }
	    })
	    
	  	//查看收款台账
        $("#button-lis").click(function(){
        	table.set();
        	var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            
            if (rows.length > 1) {
                $.modal.alertWarning("请只选择一条记录");
                return;
            }
            
            $.modal.open('确认付款',"/gcgl/qrsk/"+rows.join());
	    })
	    
	    //打印增值税发票开具申请单
	    function sqkpprint(id){
//         	table.set();
//         	var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
//             if (rows.length == 0) {
//                 $.modal.alertWarning("请至少选择一条记录");
//                 return;
//             }
            
//             if (rows.length > 1) {
//                 $.modal.alertWarning("请只选择一条记录");
//                 return;
//             }
            
            $.modal.openTab('查看',"/gcgl/sqkp/sqkpprint/"+id);
        }
        
        function sqkpfpadd(){
        	table.set();
        	var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            
            if (rows.length > 1) {
                $.modal.alertWarning("请只选择一条记录");
                return;
            }
            
            $.modal.open('新增销项发票',"/gcgl/sqkpfp/add/"+rows.join());
        }
        
        function run(processInstanceId) {
            $.modal.open("执行记录", ctx + "flow/monitor/historyDetail?processInstanceId=" + processInstanceId);
        }
        
        function traceProcess(processInstanceId) {
            $.modal.openTab("流程进度", ctx + "flow/monitor/traceProcess/"+processInstanceId);
        }
    </script>
</body>
</html>